package com.jycgame.dollmachine.wxapi;

import com.unity3d.player.*;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{
	
	private static final String TAG = "Unity";
	private final String App_ID = "wxd821faa10b80fbe9";
	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		
		Log.i(TAG, "WXPayEntryActivity onCreate");

    	api = WXAPIFactory.createWXAPI(this, App_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		Log.i(TAG, "onPayFinish, errCode = " + resp.errCode);

		UnityPlayer.UnitySendMessage("LowLevelMessageCenter", "WeChatPayCallback", String.valueOf(resp.errCode));

		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
		}

		finish();
	}
}